package controler.algorithms;

import java.util.LinkedList;

public class GMMExtraction extends Extraction {

	/**
	* {@inheritDoc}
	*/
	@Override
	public LinkedList<double[]> extract(LinkedList<double[]> dataSet) {
		
		LinkedList<double[]> set = new LinkedList<double[]>();
		double [][] tab = toArray(dataSet);
		
		for(int j=20; j<tab.length; j++)
		{
			double[] features = new double[10];
			
			int k = 0;
			features[k++] = tab[j][2];
//			features[k++] = tab[j][6];
			features[k++] = tab[j][4];
			
			for(int i=0; i<20; i++)
			{
				features[k] += tab[j - i][5];			
			}
			features[k++] /= 20.;
			
			
			for(int i=0; i<20; i++)
			{
				features[k] += Math.pow(features[k-1] - tab[j - i][5],2);	
			}
			k++;
			
			for(int i=0; i<10; i++)
			{
				features[k] += tab[j - i][5];			
			}
			features[k++] /= 10.;
			for(int i=0; i<10; i++)
			{
				features[k] += Math.pow(features[k-1] - tab[j - i][5],2);	
			}
			k++;
			
			for(int i=0; i<5; i++)
			{
				features[k] += tab[j - i][5];			
			}
			features[k++] /= 5.;
			for(int i=0; i<5; i++)
			{
				features[k] += Math.pow(features[k-1] - tab[j - i][5],2);	
			}
			k++;
			for(int i=0; i<3; i++)
			{
				features[k] += tab[j - i][5];			
			}
			features[k++] /= 3.;
			features[k++] = tab[j][5];
			set.add(features);
		}
		
		return set;
	}
	private double [][] toArray(LinkedList<double []> dataSet)
	{
		double [][] result = new double[dataSet.size()][];
		
		int i = 0;
		for(double [] tab: dataSet)
			result[i++] = tab;
		
		return result;
	}
}
